<?php
abstract class Randstand_Net_Socket_Server_Command_Manager
{
    public static function hasCommand($argCommand)
    {
        if ($argCommand == 'Manager') {
            return false;
        }
        
        $className = self::_getClassName($argCommand);
        $classFile = str_replace('_', '/', $className).'.php';
        
        if (!file_exists(dirname(__FILE__).'/../../../../../'.$classFile)) {
            return false;
        }
        
        if (!class_exists($className)) {
            return false;
        }
        
        
        
        try {
            $obj = new $className;
        }
        catch (Exception $e) {
            return false;
        }
        
        if (!method_exists($obj, self::_getMethodName($argCommand))) {
            return false;
        }
        
        return true;
    }
    
    
    public static function load($argCommand, $argArgument, Randstand_Net_Socket_Server_Client $argClient)
    {
        $className = self::_getClassName($argCommand);
        $obj = new $className;
        return call_user_method(self::_getMethodName($argCommand), $obj, $argArgument, $argClient);
    }
    
    
    private static function _getClassName($argCommand)
    {
        $chunks = explode('_', $argCommand);
        $className = 'Randstand_Net_Socket_Server_Command';
        
        foreach ($chunks as $chunk) {
           $className .= '_'.ucfirst($chunk);
        }
        
        return $className;
    }
    
    private static function _getMethodName($argCommand)
    {
    	return sprintf('%sCommand', $argCommand);;
    }
    
}
?>
